<%--
  Created by IntelliJ IDEA.
  User: 13585
  Date: 2020/12/25
  Time: 12:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<script>
    function autoLogin(){
        let ajax1;
        if(window.XMLHttpRequest){
            ajax1 = new XMLHttpRequest();
        }else {
            ajax1 = new ActiveXObject("Microsoft.XMLHttp");
        }
        ajax1.open("get","autoLogin");
        ajax1.send()
    }
    function queryMessage() {
        let ajax;
        if(window.XMLHttpRequest){
            ajax = new XMLHttpRequest();
        }else {
            ajax = new ActiveXObject("Microsoft.XMLHttp");
        }
        ajax.onreadystatechange = function(){
            if (ajax.readyState == 4 && ajax.status == 200){
                let result = ajax.responseText;
                if (result == "yes"){
                    let notice = document.getElementById("notice");
                    notice.style.display = "inline-block";
                }
            }
        }
        ajax.open("get","queryMessage");
        ajax.send()
    }
    autoLogin();
    queryMessage();
</script>
<nav class="navbar navbar-default navbar-inverse">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="index.jsp">会议室网上预约系统</a>
        </div>
        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav">
                <li><a href="index.jsp">首页</a></li>
            </ul>
            <c:choose>
                <c:when test="${!empty sessionScope.user}">
                    <ul class="nav navbar-nav navbar-right">
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">${sessionScope.user.username}<span class="caret"></span></a>
                            <ul class="dropdown-menu">
                                <li><a href="myboard.jsp">我的信息</a></li>
                                <li><a href="message">我的消息<span id="notice"></span></a></li>
                                <li><a href="update.jsp">修改密码</a></li>
                                <li role="separator" class="divider"></li>
                                <li><a href="cancel">注销</a></li>
                            </ul>
                        </li>
                    </ul>
                </c:when>
                <c:otherwise>
                    <ul class="nav navbar-nav navbar-right">
                        <li><a href="login.jsp">登录</a></li>
                        <li><a href="reg.jsp">注册</a></li>
                    </ul>
                </c:otherwise>
            </c:choose>
        </div>
    </div>
</nav>

